package fr.expdev.bndd.data;

import java.io.Serializable;
import java.util.Date;

import fr.expdev.bndd.R;

public class Post implements Serializable, Comparable<Post> {
	
	private static final long serialVersionUID = 4444613331367009517L;
	
	public enum Type {
		ANDROID(R.drawable.type_android),
		GENERAL(R.drawable.type_general),
		GWT(R.drawable.type_gwt),
		LOADING(R.drawable.type_nothing),
		NOTHING(R.drawable.type_nothing),
		SMARTY(R.drawable.type_smarty),
		SECURITY(R.drawable.type_security);
		
		private int resource;
		
		private Type(int resource) {
			this.resource = resource;
		}
		
		public int getResource() {
			return resource;
		}
	}
	
	/**
	 * ID dans la base SQLite
	 */
	private long id;
	
	private String title;
	
	private Date publicationDate;
	
	private String excerpt;
	
	private String link;
	
	private Type type = Type.NOTHING;
	
	private boolean favorite = false;

	public Post() {
		super();
	}
	
	public Post(String title, Date publicationDate, String excerpt, Type type) {
		super();
		this.title = title;
		this.publicationDate = publicationDate;
		this.excerpt = excerpt;
		this.type = type;
	}

	@Override
	public boolean equals(Object o) {
		return (o instanceof Post) && ((Post)o).getLink().equalsIgnoreCase(link);
	}

	@Override
	public int compareTo(Post another) {
		return -publicationDate.compareTo(another.getPublicationDate());
	}
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public Date getPublicationDate() {
		return publicationDate;
	}
	
	public void setPublicationDate(Date publicationDate) {
		this.publicationDate = publicationDate;
	}
	
	public String getExcerpt() {
		return excerpt;
	}
	
	public Type getType() {
		return type;
	}
	
	public void setExcerpt(String excerpt) {
		this.excerpt = excerpt;
	}
	
	public void setType(Type type) {
		this.type = type;
	}
	
	public void setType(String stringType) {
		for(Type t : Type.values()) {
			if (t.toString().equalsIgnoreCase(stringType)) {
				this.setType(t);
				break;
			}
		}
	}
	
	public String getLink() {
		return link;
	}
	
	public void setLink(String link) {
		this.link = link;
	}

	public void setFavorite(boolean favorite) {
		this.favorite = favorite;
	}

	public boolean isFavorite() {
		return favorite;
	}
}